package service;

import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.*;
import domain.Banda;

public class SimpleBandaManager implements BandaManager {
  private List<Banda> elements;

  public List<Banda> getBandas() {
    return elements;
  }

  public void setBandas(List<Banda> elements) {
    this.elements = elements;
  }

  public List<Banda> getAll(){

    return this.elements;    
  }
  
  public Banda getById(String id) {
    Iterator itr = elements.iterator();
    Banda element;
    while (itr.hasNext()) {
      element = (Banda)itr.next();
      if (element.getPk_banda().equals(id)) return element;
    }
    return null;
  }
  
  public void delete(String id){

    Iterator itr = elements.iterator();

    while (itr.hasNext()) {
      Banda element;
      element = (Banda)itr.next();
      if (element.getPk_banda().equals(id)){
        itr.remove();
  	  }
    }
  }
  
  public void insert(Banda myObj){

    if (myObj.getNombre()!=null){
      Random generator = new Random();
      int id = generator.nextInt();
	    id = Math.abs(id);
		  myObj.setPk_banda(String.valueOf(id));
		  elements.add(myObj);
    }
  }
}